import React, { Component } from 'react'

export default class App extends Component {
  state = {
    firstName: '吴',
    lastName: '大勋'
  }
  handlerChange = (event) => {
    this.setState({
      // 如果对象的key值是一个变量，就需要使用[]包裹
      [event.target.name]: event.target.value
    })
  }
  render() {
    return (
      <div>
        <input name="firstName" onChange={ this.handlerChange } value={ this.state.firstName } type="text" placeholder="姓" /> +
        <input name="lastName" onChange={ this.handlerChange } value={ this.state.lastName } type="text" placeholder="名" /> =
        { this.state.firstName + this.state.lastName }
      </div>
    )
  }
}
